package StringBuilder.exercise;

import java.util.ArrayList;
import java.util.Scanner;

//键盘录入学生的信息， 把学生信息(每个学生都有姓名和年龄)封装为 学生对象， 总共录入5个学生对象，  然后把学生对象 存入到集合中
//然后遍历集合 打印每一个学生的信息。
public class Work2 {
    public static void main(String[] args) {
        ArrayList<Student> al = new ArrayList<>();
        Student st1 = getStudent();
        Student st2 = getStudent();
        Student st3 = getStudent();
        Student st4 = getStudent();
        Student st5 = getStudent();
        al.add(st1);
        al.add(st2);
        al.add(st3);
        al.add(st4);
        al.add(st5);
        for (int i = 0; i < al.size(); i++) {
            Student str = al.get(i);
            System.out.println(str.getName() + "..." + str.getAge());
        }
    }

    private static Student getStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请录入学生姓名：");
        String name = sc.nextLine();
        System.out.println("请录入学生年龄：");
        String age = sc.nextLine();
        return new Student(name, age);
    }
}

class Student {
    private String name;
    private String age;

    public Student() {
    }

    public Student(String name, String age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}

